	<?php

/**
 * Controller_classify
 */

class Controller_classify extends MyApp {


    /** 首页 **/
    public function actionIndex()
    {

         $this->tpl->display();
    }
    /** ---------------------------------班级分类设置---------------------------------------- **/
	/** 班级分类列表 **/
    public function actionclassifyList()
    {	
		// 分页
		YOU::loadLib('page', "", '0');

		$tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_classify`");
		$count = $tmp['count'];
		$page_total = ceil($count/PAGE_LIMIT);

		// 当前页
		$p = intval($_GET['p']);
		if ($p == 0){
			$p  = 1;
		}
		if ($p > 1){
			$start = PAGE_LIMIT * ($p-1);
		}else{
			$start = 0;
		}

		$classify_lists = $this->db->fetchAll("SELECT * FROM `tbl_classify` ORDER BY classify_id DESC LIMIT {$start}, ".PAGE_LIMIT."");

		$page = new Page(array('total' => $count, 'perpage' => PAGE_LIMIT));
		$page->next_page   = '下一页>';
		$page->pre_page    = '<上一页';
		$page->style_path  = "static/page_style";

        $this->tpl->assign("page", $page->show(4, "yahoo"));
        $this->tpl->assign("classify_lists", $classify_lists);
        $this->tpl->display('classify/classify.list.tpl.php');     
    }
    /** 班级分类添加 **/
    public function actionclassifyAdd()
    {        
         if ($_POST){ 
            
            $classify_name     	= $this->post->classify_name; 

            // 写入数据库
            $info = array(       
			
            "classify_name"      	=> $classify_name,                         
            "status"                => 1,
            "create_time"           => date("Y-m-d H:i:s"),
            "update_time"           => "0000-00-00 00:00:00",  
			
            );
            $this->db->do_insert("tbl_classify", $info);

            // 跳转
            Helper_Client::location("添加成功", "index.php?a=classify.classifylist");
        }
		
        $this->tpl->display('classify/classify.add.tpl.php');
    }
    /** 班级分类修改 **/
     public function actionclassifyUpdate()
    {
       
        $classify_id   = (int)$this->get->classify_id;
        $classify_data = $this->db->fetchRow("SELECT * FROM `tbl_classify` WHERE `classify_id`='{$classify_id}'");
	
        if (empty($classify_data)){
            Helper_Client::alert("班级分类不存在");
        }

        if ($_POST){
            
            $classify_name        = $this->post->classify_name;
     
            // 写入数据库
            $info = array(  
    
            "classify_name"     	=> $classify_name,                    
            "status"                => 1,
            "create_time"           => date("Y-m-d H:i:s"),
            "update_time"           => "0000-00-00 00:00:00",           
            );
            $this->db->do_update("tbl_classify", $info, "classify_id='{$classify_id}'");
      
            // 跳转
            Helper_Client::location("修改成功", "index.php?a=classify.classifylist");
        }
    
        $this->tpl->assign("classify_data", $classify_data);
        $this->tpl->display('classify/classify.update.tpl.php');
    } 
    /** 班级分类删除 **/
    public function actionclassifyDel()
    {	
        $classify_id = $this->get->classify_id;   
        $this->db->query("DELETE  FROM `tbl_classify` WHERE classify_id='{$classify_id}'");
        
        // 跳转
        Helper_Client::location("删除成功", "index.php?a=classify.classifylist");
    }

   
}
	
?>